from django.http import JsonResponse, FileResponse, HttpResponseNotFound

from server.utils import Code


class Response:
    """ Custom http Response """

    @classmethod
    def Json(cls, **kwargs):
        """ Response in JSON format """
        code, msg = kwargs.pop('code', Code.OK)
        data = {
            'code': code,
            'msg': msg,
            **kwargs
        }
        return JsonResponse(data)

    @classmethod
    def Image(cls, image=None):
        """ Response in image format """
        if not image:
            return HttpResponseNotFound()
        return FileResponse(image)
